package com.sunny.ynhz.ui.patrol.problems;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;

import com.sunny.ynhz.R;
import com.sunny.ynhz.adapter.OfficeAdminAdapter;
import com.sunny.ynhz.api.HttpManager;
import com.sunny.ynhz.api.subscriber.ApiSubscriber;
import com.sunny.ynhz.bean.OfficeAdminBean;
import com.sunny.ynhz.ui.base.AppBaseTranslationTitleBarActivity;
import com.sunny.ynhz.utils.SPUtil;

import java.util.LinkedList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import rx.android.schedulers.AndroidSchedulers;
import rx.schedulers.Schedulers;

/**
 * Created by luao on 2017/8/4.
 */

public class OfficeAdminActivity extends AppBaseTranslationTitleBarActivity {


    @BindView(R.id.recycler)
    RecyclerView recycler;
    private OfficeAdminAdapter officeAdminAdapter;
    private LinkedList<OfficeAdminBean.DataBean> officeAdminBean;


    public static void ToOfficeAdminActivity(Activity context) {
        Intent intent = new Intent(context, OfficeAdminActivity.class);
        context.startActivityForResult(intent, 100);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_office_admin);
        ButterKnife.bind(this);
        setTitle("提交对象");

        officeAdminBean = new LinkedList<>();

        LinearLayoutManager linearLayoutManager = new LinearLayoutManager(this);
        recycler.setLayoutManager(linearLayoutManager);
        officeAdminAdapter = new OfficeAdminAdapter(officeAdminBean);
        recycler.setAdapter(officeAdminAdapter);
//        getData("13602299426");
       String string =  SPUtil.get("addvcd","null").toString();
        getData(SPUtil.get("addvcd","null").toString());
    }

    private void getData(String addvcd) {
        HttpManager.getInstance()
                .getAreaList(addvcd)
                .subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread())
                .subscribe(new ApiSubscriber(this, new ApiSubscriber.HttpOnResultListener<OfficeAdminBean>() {
                    @Override
                    public void onNext(OfficeAdminBean jsonObject) {
                        if (jsonObject.getData() != null) {
                           List<OfficeAdminBean.DataBean.RiverchiefBean> officeAdminBean1 = jsonObject.getData().getRiverchief();
                            officeAdminBean.clear();
                            officeAdminBean.add(jsonObject.getData());
                            officeAdminBean.add(jsonObject.getData());
                            officeAdminBean.add(jsonObject.getData());
                            officeAdminBean.add(jsonObject.getData());
                            officeAdminAdapter.notifyDataSetChanged();
                        }
                    }

                    @Override
                    public void onCompleted() {

                    }

                    @Override
                    public void onstart() {

                    }

                    @Override
                    public void onError(Throwable e) {
                        super.onError(e);
                    }
                }));
    }
}
